const { Sequelize } = require("sequelize");
const { isRequired } = require("../utils");

module.exports = (sequelize, DataTypes) => {
  const mapArea = sequelize.define(
    "Area",
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: Sequelize.UUIDV4,
        //是否允许为空
        allowNull: false,
        //是否为主键
        primaryKey: true,
        //备注
        comment: "区域id",
      },
      parentId: {
        type: DataTypes.UUID,
        comment: "父级id",
        allowNull: true,
      },
      areaName: {
        type: DataTypes.STRING,
        comment: "区域名称",
        allowNull: false,
        validate: isRequired("区域名称"),
      },
      picUrl: {
        type: DataTypes.STRING,
        comment: "图片地址",
      },
      sort: {
        type: DataTypes.INTEGER,
        comment: "排序",
        defaultValue: 0,
      },
    },
    {
      timestamps: true,
      tableName: "map_area",
      createdAt: "createTime",
      updatedAt: "updateTime",
      comment: "区域表",
    }
  );
  return mapArea;
};
